package com.example.administrator.qimo3no74.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.example.administrator.qimo3no74.R;
import com.example.administrator.qimo3no74.shopping_cart.ShoppingItem;
import com.example.administrator.qimo3no74.shopping_cart.ShoppingItemAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShoppingCartFragment extends Fragment {

    private List<ShoppingItem> shoppingItems = new ArrayList<>();

    public ShoppingCartFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_shopping_cart, container, false);
        //结算按钮方法
        buttonAction(view);
        //内容方法
        intiShoppingItem();
        actionShoppingItem(view);


        return view;
    }


    private void buttonAction(View view) {
        Button button = view.findViewById(R.id.balanceButton);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "你点了结算按钮", Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void actionShoppingItem(View view) {
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.shoppingCartRecyclerView);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        ShoppingItemAdapter adapter = new ShoppingItemAdapter(shoppingItems);
        recyclerView.setAdapter(adapter);
    }

    private void intiShoppingItem(){
        shoppingItems.add(new ShoppingItem("毛呢背心裙秋冬女2018新款修身显瘦中长款背带无袖打底马甲A字裙",129.00,2,"百魅女人屋",R.drawable.beixin_qun1,"毛呢背心裙秋冬女2018新款修身显瘦中长款背带无袖打底马甲A字裙"));
        shoppingItems.add(new ShoppingItem("抹茶故事工装棉服男中长款2018新款棉衣韩版潮流棉袄ins冬季外套",388.00,1,"抹茶故事旗舰店",R.drawable.mocha_gushi,"抹茶故事工装棉服男中长款2018新款棉衣韩版潮流棉袄ins冬季外套"));
        shoppingItems.add(new ShoppingItem("骆驼男装 2018秋冬新款青年纯色中长款加厚外套可脱卸帽羽绒服男",1198.00,1,"骆驼男装旗舰店",R.drawable.luotou_nan,"骆驼男装 2018秋冬新款青年纯色中长款加厚外套可脱卸帽羽绒服男"));
        shoppingItems.add(new ShoppingItem("毛呢背心裙秋冬女2018新款修身显瘦中长款背带无袖打底马甲A字裙",129.00,5,"百魅女人屋",R.drawable.beixin_qun1,"毛呢背心裙秋冬女2018新款修身显瘦中长款背带无袖打底马甲A字裙"));
        shoppingItems.add(new ShoppingItem("毛呢背心裙秋冬女2018新款修身显瘦中长款背带无袖打底马甲A字裙",129.00,1,"百魅女人屋",R.drawable.beixin_qun1,"毛呢背心裙秋冬女2018新款修身显瘦中长款背带无袖打底马甲A字裙"));
    }


}
